#ifndef __CSFX_H__
#define __CSFX_H__

#include "Stream/CMpcStream.h"
#include "CTrackStereo.h"

#include <string>

using namespace std;

////////////////////////////////////////////////////////////////////////
//*******************************************************************
//	class CSfx:
//*******************************************************************
////////////////////////////////////////////////////////////////////////
class CSfx
{
public:
	enum
	{
		kInvalid = 0,
		kPlaying = 1,
		kLooping = 2,
	};

private:
	std::string		m_filename;
	CMpcStream*		m_mpcStream;
	CTrackStereo*	m_track;
	audio::s8*		m_buffer[CTrackStereo::NUM_BUFFER];
	int				m_bufferSize;
	int				m_currentBuffer;
	int				m_channel;
	int				m_rate;
	int				m_period;
	int				m_nLoop;
	int				m_nStaticSample;

	bool			m_isStatic;
	audio::u32		m_lastUpdateTime;

	int ConvertGlobalIdToSfxId(int globalIndex) const;

	int m_status;	

public:
	CSfx();
	~CSfx();

	void Init(std::string filename, bool isStatic = false);
	CTrackStereo* getTrack();
	void ReadWholeBuffer();
	void EmptyBuffer();
	void CleanUp();

	void Play(int loop = 1, int period = 0 );
	void Stop();
	void Pause();
	void Unpause();
	void Restart();

	void Update();
	void SetVolumeGain(float gain);
	void SetVolume(int volume);

	bool ReInitSoundInstance(void);
	int GetStatus() const;

	void setLoop(bool loop);

	bool isStatic() const { return m_isStatic; }

private:
	void InitStatic();
	void PlayStatic();
	void PlayStream();
	void RestartStatic();
	void RestartStream();

};

#endif //__CSFX_H__
